package com.tiantian.quanminxiu.presenter;

import com.shenglian.utils.utils.CommonUtils;
import com.tiantian.quanminxiu.api.AnchorService;
import com.tiantian.quanminxiu.utils.ApplicationBase;
import com.tiantian.quanminxiu.utils.Constants;
import com.tiantian.quanminxiu.utils.UserData;
import com.tiantian.quanminxiu.view.NotLiveView;

import rx.android.schedulers.AndroidSchedulers;

/**
 * Created by admin on 2016/8/11.
 */
public class NotLivePresent implements Presenter<NotLiveView> {

    private NotLiveView notLiveView;

    @Override
    public void attachView(NotLiveView view) {
        this.notLiveView = view;
    }

    @Override
    public void detachView() {
        notLiveView = null;
    }


    public void InitAnchotList(int iDisplayStart,int iDisplayLength){
        notLiveView.Loading_Open();
        ApplicationBase app = ApplicationBase.get(notLiveView.getContext());
        AnchorService service = app.getAnchorService();
        service.user_useranchor_listhot(UserData.Current.mid,UserData.Current.sign, Constants.APP_TYPE,iDisplayStart,iDisplayLength)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(app.defaultSubscribeScheduler())
                .finallyDo(()->{
                    notLiveView.Loading_Close();
                })
                .subscribe(str -> {
                    if (notLiveView!=null){
                        notLiveView.getAnchorList(str.optJSONArray("data"),iDisplayStart+iDisplayLength);
                    }
                }, throwable -> {
                    if (notLiveView!=null){
                        CommonUtils.showToask(notLiveView.getContext(),"获取列表失败:"+throwable.getMessage());
                    }
                });

    }
}
